package com.shenhaofeng.app.device;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.RequiresApi;

import java.util.Arrays;


/**
 * Created by Administrator on 2016/10/12.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class DeviceInfo {


    /**
     * 获取手机型号
     *
     * @return 手机型号 例如:xt1085
     */
    public static String getDeviceModel() {
        return Build.MODEL;
    }


    /**
     * 获取android系统版本
     *
     * @return android系统版本 例如:5.1
     */
    public static String getAndroidVersion() {
        return Build.VERSION.RELEASE;
    }


    /**
     * 获取设备系统版本号
     *
     * @return
     */
    public static int getAndroidSDK() {
        return Build.VERSION.SDK_INT;
    }


    /**
     * 获取系统定制商
     *
     * @return
     */
    public static String getBrand() {
        return Build.BRAND;
    }


    /**
     * 获取基础板名/(技术解决方法...可能)
     *
     * @return
     */
    public static String getBoard() {
        return Build.BOARD;
    }


    /**
     * 获取产品/硬件的生产商
     *
     * @return
     */
    public static String getManufacturer() {
        return Build.MANUFACTURER;
    }


    /**
     * 修订版本列表
     *
     * @return
     */
    public static String getId() {
        return Build.ID;
    }


    /**
     * 用户可见的一个构建版本ID名,这里指的是在设置中关于手机下的版本号
     *
     * @return
     */
    public static String getDisplay() {
        return Build.DISPLAY;
    }


    /**
     * 获取基带版本名
     *
     * @return
     */
    public static String getRadio() {
        return Build.getRadioVersion();
    }


    /**
     * 获取硬件名称(如qcom)
     *
     * @return
     */
    public static String getHardware() {
        return Build.HARDWARE;
    }


    /**
     * 获取唯一识别码
     *
     * @return
     */
    public static String getFingerprint() {
        return Build.FINGERPRINT;
    }


    /**
     * 获取硬件序列号
     *
     * @return
     */
    public static String getSerial() {
        return Build.SERIAL;
    }


    /**
     * 获取整个产品的名称
     *
     * @return
     */
    public static String getProduct() {
        return Build.PRODUCT;
    }


    /**
     * 获取系统启动(引导)程序的版本号
     *
     * @return
     */
    public static String getBootloader() {
        return Build.BOOTLOADER;
    }


    /**
     * 返回所有支持的cpu指令集的名称
     *
     * @return
     */
    public static String[] getSupportedABIS() {
        if (Build.VERSION.SDK_INT >= 21) {
            return Build.SUPPORTED_ABIS;
        } else {
            return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
        }
    }


    /**
     * 返回最优先的CPU指令集
     *
     * @return
     */
    public static String getMostPreferredABI() {
        if (Build.VERSION.SDK_INT >= 21) {
            return Build.SUPPORTED_ABIS[0];
        } else {
            return Build.CPU_ABI;
        }
    }


    /**
     * 获取所有支持的32位指令集名称
     *
     * @return
     */
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public static String[] getSupported32BitABIS() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            return Build.SUPPORTED_32_BIT_ABIS;
        } else {
            return new String[0];
        }
    }


    /**
     * 获取所有支持的64位指令集名称
     *
     * @return
     */
    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    public static String[] getSupported64BitABIS() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            return Build.SUPPORTED_32_BIT_ABIS;
        } else {
            return new String[0];
        }
    }


    /**
     * 当前开发代号
     *
     * @return
     */
    public static String getCodeName() {
        return Build.VERSION.CODENAME;
    }


    public static String getIncremental() {
        return Build.VERSION.INCREMENTAL;
    }


    /**
     * 转换为一个拼接好的设备信息字符串
     *
     * @return
     */
    public static String toDeviceInfoString() {

        return "id:" + getId() + "\n"
                + "brand:" + getBrand() + "\n"
                + "device:" + getDeviceModel() + "\n"
                + "android_version:" + getAndroidVersion() + "\n"
                + "android_sdk_version:" + getAndroidVersion() + "\n"
                + "board:" + getBoard() + "\n"
                + "display:" + getDisplay() + "\n"
                + "serial:" + getSerial() + "\n"
                + "product:" + getProduct() + "\n"
                + "manufacturer:" + getManufacturer() + "\n"
                + "radio:" + getRadio() + "\n"
                + "hardware:" + getHardware() + "\n"
                + "fingerprint:" + getFingerprint() + "\n"
                + "bootloader:" + getBootloader() + "\n"
                + "cpu_abis:" + Arrays.toString(getSupportedABIS()) + "\n"
                + "cpu_abis_most_preferred:" + getMostPreferredABI() + "\n"
                + "codename:" + getCodeName() + "\n"
                + "incremental:" + getIncremental() + "\n";


    }

}
